<?php
namespace app\api\controller;
use think\Db;
class User extends Common
{
	public function __construct()
    {
	  parent::__construct();
    }
    public function index()
    {
		echo '我是api';
    }
//    用户登录
    public function login(){
        $para = get_json_data();
        $where['username']=$para['data']['username'];
        $re=Db::table('xb_mem_info')->where($where)->find();
        if(!$re){
            show(0,'未注册的手机号');
        }
        if(md5($para['data']['Password'])==$re['Password']){
            show();
        }else{
            show(0,'登录名和密码不匹配');
        }
    }
//    用户注册
    public function reg(){
        $para = get_json_data();
        $para1=$para['data'];
        //手机号码格式不正确
        if(!is_mobile($para1['mobile'])){
            show(0,'很抱歉，手机号码格式不正确！');
        }
        //密码不能为空
        if(!$para1['pwd']){
            show(0,'很抱歉，密码不能为空！！');
        }
        $where['mobile']=$para1['mobile'];
        $where['IsDel']='0';
        $re=Db::table('xb_mem_info')->where($where)->find();
        if($re){
            show(0,'很抱歉，此用户已存在！');
        }
        //注册来源
        $Retype='1';//默认是 安卓
        if($para['client']=='ios'){
            $Retype='2';
        }
        $data=array(
            'UserName'=>$para1['mobile'],
            'NickName'=>'guser_'.rand(),
            'Mobile'=>$para1['mobile'],
            'Password'=>md5($para1['pwd']),
            'Retype'=>$Retype,
            'RegTime'=>date('Y-m-d H:i:s')
        );
        $re1=Db::table('xb_mem_info')->insertGetId($data);
        if($re1){
            show();
        }else{
            show(0,'很抱歉，操作失败，请稍后再试');
        }

    }

}
